/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entities;


import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author JackOddie
 */
public class User {
    private String id_user;
    private String password;
    private String nama_user;
    private String alamat;
    private String jabatan;
    
    public User(){
        
    }
    public User(String id_user,String password){
        this.id_user=id_user;
        this.password = password;
    }

    public static boolean isExist(String id,String password) throws SQLException {
        DBConnection conn=new DBConnection();
        
        String query = "select * from USERLOGIN where ID_USER='" + id + "' AND PASSWORD= '" + password + "' and islogin='0'";
        ResultSet rset = conn.select(query);
        if (rset.next() == false) {
            return false;
        }
        return true;
    }
    public void toggleLogin() throws SQLException{
        DBConnection conn=new DBConnection();
        
        String query = "update USERLOGIN set islogin='1' where ID_USER='"+id_user+"'";
        conn.updateData(query);
        
    }
    public void toggleLogout() throws SQLException{
        DBConnection conn=new DBConnection();
        
        String query = "update USERLOGIN set islogin='0' where ID_USER='"+id_user+"'";
        conn.updateData(query);
        
    }
    
    public String getId_user() {
        return id_user;
    }

    public void setId_user(String id_user) {
        this.id_user = id_user;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getNama_user() {
        return nama_user;
    }

    public void setNama_user(String nama_user) {
        this.nama_user = nama_user;
    }

    public String getAlamat() {
        return alamat;
    }

    public void setAlamat(String alamat) {
        this.alamat = alamat;
    }

    public String getJabatan() {
        return jabatan;
    }

    public void setJabatan(String jabatan) {
        this.jabatan = jabatan;
    }
    
    public void getAllData() throws SQLException {
        DBConnection conn=new DBConnection();
        
        String query = "select * from USERLOGIN where ID_USER='" + getId_user() + "' AND PASSWORD='" + getPassword() + "'";
        ResultSet rset = conn.select(query);
        while (rset.next()) {
            id_user = rset.getString("ID_USER");
            password = rset.getString("PASSWORD");
            nama_user = rset.getString("NAMA_USER");
            alamat = rset.getString("ALAMAT");
            jabatan = rset.getString("JABATAN");
            
        }
    }
}
